#include<bits/stdc++.h>
using namespace std;
typedef long long int
bool st;
const int N=25;
int tt,n,a[N],c[N],lst[N],l[N];
int read(int &x){
    x=0;
    char c=0;
    bool f=1;
    while(!isdigit(c)){
        f&=(c!='-');
        c=getchar();
    }
    while(isdigit(c)){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    x=(f?x:-x);
}
void print_l(){
    cout<<"lst: \n";
    for(int i=1;i<=n;i++){
        cout<<l[a[i]]<<" ";
    }
    cout<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    read(tt);
    while(tt--){
        int ans=0;
        read(n);
        memset(lst,0,sizeof lst);
        for(int i=1;i<=n;i++){
            read(a[i]);
            l[i]=lst[a[i]];
            if(l[i]==0){
                l[i]=i;
            }
            lst[a[i]]=i;
            //cout<<"i: "<<i<<" a: "<<a[i]<<" lst: "<<l[i]<<endl;
        }
        //print_l();
        int sum=0;
        memset(c,0,sizeof c);
        for(int s=0;s<(1<<n);s++){
            sum=0;
            for(int i=1;i<=n;i++){
                if(l[i]!=i){
                    int x=s&(1<<i);
                    int y=s&(1<<l[i]);
                    if(x==y){
                        sum+=a[i];
                    }
                }
            }
            ans=max(ans,sum);
        }
        printf("%lld\n",ans);
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
